package com.lcx.db137.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lcx.db137.common.R;
import com.lcx.db137.entity.Rolemenu;
import com.lcx.db137.service.impl.RolemenuServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
* (rolemenu)表控制层
*
* @author xxxxx
*/
@RestController
@CrossOrigin(origins = "*")
public class RolemenuController {
/**
* 服务对象
*/
@Autowired
private RolemenuServiceImpl rolemenuServiceImpl;
//根据角色id查询菜单id
    @GetMapping("/selectmenuIdByRoleId")
    public R selectMenuIdByRoleId(Integer roleId) {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("roleid", roleId);
        List<Rolemenu>  roles =  rolemenuServiceImpl.list(queryWrapper);
        return new R().add("menuId", roles);
    }
    //根据角色id修改对象的菜单id集合
    @PostMapping("/updateMenuIdByRoleId")
    public R updateMenuIdByRoleId(@RequestBody Map<String,Object> map) {
        System.out.println("map = " + map);
        int roleid=Integer.parseInt(map.get("roleid")+"");//角色id
        List<Integer> listMenu= (List<Integer>) map.get("listMenu");
        boolean boo=rolemenuServiceImpl.updateMenuIdByRoleId(roleid,listMenu);
        System.out.println("listMenu = " + listMenu);
        System.out.println("roleid = " + roleid);
        return new R().add("boo",boo);
    }

    
}
